<!doctype html>
<?php
 	error_reporting(E_ALL & ~E_NOTICE);
	session_start();
	include("conn.php");
	?>
<html>
<head>
 <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>集鲜蜂商城</title>
    <link rel="stylesheet" href="shopcss/common.css" />
    <link rel="stylesheet" href="shopcss/header.css" />
    <link rel="stylesheet" href="shopcss/goodsList.css" />
    <link rel="stylesheet" href="shopcss/defaul.css" />
    	<link rel="stylesheet" href="canico.css">
</head>
</head>
<body>
    <header>
        <div id="head-top"  style="margin-top: 5px;">
            <nav class="clearfix">

	  <div class="location" style="">
       <span>地区 ： </span>
      <i class="cd-location">&nbsp;<input type="text" class="selectBoxPub_r flightto" style="border:none;width:50px;background-color:#e6e3e6; font-size: 12px;"></i>
</div>		  
	  
				  
				  
                <ul class="right clearfix" style="">
                   <li class="menu welcome">
                       <?php
						if(!empty($_SESSION['identity'])){
                       echo "<a href='index.php' class='link-login'>主页</a>";}
						
					else{
							echo "<a href='login.php' class='link-login'>你好，请登录</a>";
						}
						
						?>
                    
                    </li>
                    <li class="spacer">|</li>
                    <li class="menu red"><a href="myorder.html" style="color:#999">加入我们</a></li>
                    <li class="spacer">|</li>
                    <li class="menu red">
                    <?php
					if(!empty($_SESSION['identity'])){
                    echo "<a href='myorder.php'>我的订单&nbsp;∨</a>";}
					else{
						 "<a href='#'>我的订单&nbsp;∨</a>";
					}
                    ?>
                    </li>
                    <li class="spacer">|</li>
                    <li class="menu red">企业合作</li>
                    <li class="spacer">|</li>
                    <li class="menu qiye">餐饮采购&nbsp;∨</li>
                    <li class="spacer">|</li>

                </ul>
            </nav>
        </div>
        <div class="w clearfix">
            <div id="logo">
                <a href="index.html"><img src="img/logo.png" ></a>
            </div>
            <div id="search">
                <!-- 搜索列表  已隐藏 -->
                <ul class="menu" id="shelper"></ul>
                <div class="form">
                    <input type="text" id="key" value="水果" class="text blurcolor">
                    <i class="fa fa-camera"></i>
                    <button>搜索</button>
                </div>
            </div>
            <div id="settleup" class="dropdown">
                <div class="cw-icon">
                    <i class="fa fa-shopping-cart car"></i>
                    <i class="i-count" id="count">0</i>
                    <a href="gwc.php">我的购物车</a>
                </div>
                
            </div>
            <div id="hotwords" class="haveline clearfix">
                <a href="#">香蕉</a>
                <b>|</b>
                <a href="#">苹果</a>
                <b>|</b>
                <a href="#">牛奶</a>
                <b>|</b>
                <a href="#">酸奶</a>
                <b>|</b>
                <a href="#">车厘子</a>
                <b>|</b>
                <a href="#">水果礼盒</a>
                <b>|</b>
                <a href="#">葡萄</a>
                <b>|</b>
                <a href="#">柚子</a>
                <b>|</b>
                <a href="#">橙子</a>
                <b>|</b>
                <a href="#">榴莲</a>

            </div>
        </div>
    </header>
    <section>
        <div id="nav">
            <div class="w clearfix">
                <div id="categorys" style="height: auto; left: 0px; position: absolute;">
                    <div class="dt">
                        <a href="#">热销商品</a>
                    </div>
                    <div class="dd" style="display: none;"></div>
                </div>
                <div id="navitems" class="clearfix">
                    <ul class="navitems-group1 clearfix">
                        <li><a href="#">菜市场</a></li>
                        <li><a href="#">超市</a></li>
                        <li><a href="#">个体菜农</a></li>
                    </ul>
                    <div class="spacer"></div>
                    <ul class="navitems-group2 clearfix">
                        <li><a href="#">优惠购</a></li>
                        <li><a href="#">异地购</a></li>
                        <li><a href="#">菜谱购</a></li>
                    </ul>
                    <div class="spacer"></div>
                    <ul class="navitems-group3 clearfix">
                        <li><a href="#">上新</a></li>
                    </ul>
					<div class="spacer"></div>
                    <ul class="navitems-group3 clearfix">
                        <li><a href="#">活动</a></li>
                    </ul>
				
					<ul class="navitems-group3 clearfix">
                        <li><a href="#">其他</a></li>
                    </ul>
                </div>
            </div>
        </div>
		
			<div class="shicai-body">
				<ul>
					<li>
						<a href="">
							<img src="img/shicai/shicai1.jpg"/>
							韭菜
						</a>
						<span>春季第一补</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai2.jpg"/>
							菠菜
						</a>
						<span>红嘴绿鹦哥</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai3.jpg"/>
							草莓
						</a>
						<span>享受“莓”好时光</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai4.jpg"/>
							春笋
						</a>
						<span>春味醉春盘</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai5.jpg"/>
							菠萝
						</a>
						<span>凤梨是谁？</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai6.jpg"/>
							莴笋
						</a>
						<span>笋中卧底</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai7.jpg"/>
							黑木耳
						</a>
						<span>八朵木耳一身轻</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai8.jpg"/>
							皮皮虾
						</a>
						<span>海鲜界的网红</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai9.jpg"/>
							螺蛳
						</a>
						<span>四月螺，赛过鹅</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai10.jpg"/>
							鳜鱼
						</a>
						<span>宜香宜臭</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai11.jpg"/>
							鸡胸肉
						</a>
						<span>瘦身最佳肉类伴侣</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai12.jpg"/>
							生蚝
						</a>
						<span>海中牛奶</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai13.jpg"/>
							猪肝
						</a>
						<span>补铁好搭档</span>
					</li>
					<li>
						<a href="">
							<img src="img/shicai/shicai14.jpg"/>
							排骨
						</a>
						<span>可记得吮指之乐</span>
					</li>
				</ul>
			</div>
       
            <?php
   
	$name=$_GET['name'];
	$pagesize = 12 ;//每页最多显示3条记录
	$sqlTotal = "select storename,goodsid,goodsname,price,picture,type,market,goodssale
	                         from goods
		    where type ='$name'";
  
	$totalQuery = mysqli_query($conn,$sqlTotal); //执行查询语句
	$totalNum   = mysqli_num_rows($totalQuery); //查询总记录数
	$pageCount  = ceil($totalNum/$pagesize);  //总页数	
	//获取当前显示页数
    (!isset($_GET['page']))?($currentPage = 1):$currentPage = $_GET['page']; 
	//当前页大于总页数时把当前页定义为总页数 (有疑问？输入大于的数字？)
	($currentPage <= $pageCount)?$currentPage:($currentPage = $pageCount);
	//当前页的第一条记录
	$f_pageNum = $pagesize * ($currentPage - 1);
	
	//定义SQL语句，通过limit关键字控制查询范围和数量
	$sqlLimit =$sqlTotal." limit ".$f_pageNum.",".$pagesize;
	
	$goods = array();
	$result = mysqli_query($conn,$sqlLimit);
	if($result==1){
	while ($row = mysqli_fetch_row($result))
	{	
    $goods[$i]['storename'] = $row[0];
	$goods[$i]['goodsid'] = $row[1];	
    $goods[$i]['goodsname'] = $row[2];
    $goods[$i]['price'] = $row[3];
	$goods[$i]['picture']=$row[4];
	$goods[$i]['market']=$row[6];
	$goods[$i]['goodssafe']=$row[7];
    $i++;
	}}
		else{
			echo "暂无该商品出售";
		}
?>

        <div id="J_searchWrap" class="w">
                <div id="J_main" class="main  clearfix">
                    <div class="m-list">
                        <div class="ml-wrap">
                          
                            <div id="J_goodsList" class="goods-list">						
						    <h2 style="margin-left: -120px;margin-top: -30px;">商品列表</h2>
                           <ul class='gl-warp clearfix' style="margin-top: 20px;">
                   <?php 
					foreach ($goods as $value) { 
                            /* echo    "<ul class='gl-warp clearfix'>";*/
                              echo   "<li class='gl-item'>";
                              echo    "<div class='gl-i-wrap'>";
                              echo     "<div class='p-img' style='margin-top:-15px;'>
                                                <a href='#' >
			<img src='img/".$value['picture']."'  alt='' width='220' height='220' ></a>
                                         </div>";
                              echo      "<div class='p-price'>
                                                <strong>
                                                    <em>￥</em>
                                                    <i>".$value['price']."</i>
                                                </strong>
                                           </div>";
                              echo         "<div class='p-name'>
                                                <a href='#'>
                                                    <em>
                                                        <span class='p-tag'>".$value['market']."</span>
														<span class='p-tag'>摊位-A103</span>
														<span class='p-tag'>3星商户</span>
                                                        
                                                    </em>
                                                </a>
                                            </div>";
                              echo           "<div class='p-commit'>
                                                <strong><a href='#'>43+</a>".$value['goodssafe']."</strong>
                                            </div>";
                              echo           "<div class='p-shop'>
                                                <span>
                                                    <a href='#' >".$value['storename']."</a>
                                                 </span>   
                                            </div>";
                              echo              "<div class='p-icons clearfix'>
                                                <i class='goods-icons' >热销商品</i>
                                                <i class='goods-icons'>优惠购</i>
                                                <i class='goods-icons4'>新鲜保证</i>
                                                <i class='goods-icons4'>2020-3-20</i>
                                            </div>";
						if(!empty($_SESSION['identity'])){
                              echo              "<div class='p-operate clearfix'>
                                               
            <a href=collectiontest.php?goodsname=" . $value['goodsname'] . '&storename=' . $value['storename'] .'&price=' . $value['price'] . '&picture=' . $value['picture'] ." class='p-o-btn'>
            <i calss='fa fa-heart' target='_blank'>♥&nbsp</i>收藏</a>
            <a href=gwcgo.php?goodsname=" . $value['goodsname'] . '&price=' . $value['price'] . '&picture=' . $value['picture'] . '&storename=' . $value['storename'] . '&market=' . $value['market'] ."  class='p-o-btnn' target='_blank'>  加入购物车 </a>
			            
                                                 </div>";}
						else{
						echo  "<div class='p-operate clearfix'>
                              <a href=login.php?class='p-o-btnn'>请先登录</a>
							  <br>
                              </div>";
						
						}
                                echo        "</div>";
                                echo        "</li>";
                           
 /* echo "<p class='btn'><a href=gwcgo.php?goodsname=" . $value['goodsname'] . '&price=' . $value['price'] .">加入购物车</a><p>"; 
	echo "<p class='btn'><a href=collectiontest.php?goodsname=" . $value['goodsname'] . '&storename=' . $value['storename'] .'&price=' . $value['price'] .">收藏</a><p>";   */                              
                                /*echo    "</ul>";*/}  ?>
                                </ul>
                            </div>
                            
                        </div>
                    </div>
                   
                </div>
            <div class="ye">
 <?php
	  echo "<div style='margin-left: -120px;margin-top: -10px;font-size:20px;'>";
	   echo "<tr>";
	    echo '<td height="25" colspan="6" align="right">';
		echo "共".$totalNum."有个商品&nbsp;&nbsp;";
	    echo "第".$currentPage."页/共".$pageCount."页&nbsp;&nbsp;";
		if($currentPage!=1)
		{
		   //如果当前页不是1则输出有链接的首页和上一页
	       echo "<a href='?page=1 &name=$name'>首页</a>&nbsp;";
		   echo "<a href='?page=".($currentPage-1)."&name=$name'>上一页</a>&nbsp;&nbsp;";
	    }else{
			  //否则输出没有链接的首页和上一页

	            echo "首页&nbsp;上一页&nbsp;&nbsp;";
	         }
		
		if($currentPage!=$pageCount)
		{
		  //如果当前页不是最后一页则输出有链接的下一页和尾页
	      echo "<a href='?page=".($currentPage+1). "&name=$name'>下一页</a>&nbsp;";
		  echo "<a href='?page=".$pageCount."&name=$name'>尾页</a>&nbsp;&nbsp;";
	    }else{
			   //否则输出没有链接的下一页和尾页
	            echo "下一页&nbsp;尾页&nbsp;&nbsp;";
	          }
	
	            echo "</br>";
				echo "</div>";
?>
			
			</div>
        </div>
           </section>
          
</body>
</html>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/velocity.min.js"></script>
<script src="js/myjs.js"></script>
<script src="js/goodsList.js"></script>
<script src="./js/location.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=eFaNjhaFcBEWaqwqs3N5ziq4PKUClOiY"></script>
 <script>
			var isLocate = false; //判断是否定位

			var flightto = document.querySelector(".flightto");
			//获取地理位置定位
			function locateMe() {
				var geolocation = new BMap.Geolocation();
				geolocation.getCurrentPosition(function(r) {
					if(this.getStatus() == BMAP_STATUS_SUCCESS) {
						isLocate = true;
						var url = "http://api.map.baidu.com/geocoder/v2/" +
							"?callback=renderReverse&location=" + r.point.lat + "," + r.point.lng + "&output=json&pois=1&ak=eFaNjhaFcBEWaqwqs3N5ziq4PKUClOiY";
						var JSONP = document.createElement("script");
						JSONP.src = url;
						document.body.appendChild(JSONP);
					} else {
						alert('failed' + this.getStatus());
					}
				}, {
					enableHighAccuracy: true
				})
			}
			locateMe();

			function renderReverse(r) {
				flightto.value = r.result.addressComponent.city;
				console.log(r);
			}
		</script>
